﻿using System;
using Microsoft.Practices.ObjectBuilder2;
using Microsoft.Practices.Unity;

namespace UniAspect.UnityCommon.OptionalDependency
{
    public class OptionalParameter : InjectionParameterValue
    {
        private readonly string _name;
        private readonly Type _type;

        public OptionalParameter(Type type)
                : this(type, null)
        { 
        }
        public OptionalParameter(Type type, string name)
        {
            _type = type;
            _name = name;
        }

        public override IDependencyResolverPolicy GetResolverPolicy()
        {
            return new OptionalDependencyResolver(_type, _name);
        }

        public override Type ParameterType
        {
            get { return _type; }
        }
    }

    public class OptionalParameter<T> : OptionalParameter
    {
        public OptionalParameter()
                : base(typeof(T))
        {

        }

        public OptionalParameter(string name)
                : base(typeof(T), name)
        {
        }
    }
}